﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LardonPokerSimulator.Model
{
    public interface IIteratorPlayer
    {
        void FirstPlayer();
        void NextPlayer();
        bool IsDone();
        Player CurrentPlayer();
    }

    
    public class IteratorPlayer : IIteratorPlayer
    {
        private bool _inifite = true; 
        private int _index = 0;

        public IteratorPlayer()
        { }

        public IteratorPlayer(bool aInfinite)
        {
            this._inifite = aInfinite;
        }

        public void FirstPlayer()
        {
            this._index = 0;
        }

        public void NextPlayer()
        {
            this._index++;


            if (this._inifite && this._index >= Table.TableInstance.Players.Length)
            {
                this.FirstPlayer();
            }

        }

        public bool IsDone()
        {
            if (this._inifite)
            {
                return false;
            }

            return Table.TableInstance.Players.Length >= this._index;
        }

        public Player CurrentPlayer()
        {
            return Table.TableInstance.Players[this._index];
        }
    }
}
